package com.dtstack.mongodb.facade;

import com.dtstack.mongodb.domain.document.ArticleDocument;
import com.dtstack.mongodb.repository.ArticleDocumentRepository;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * ArticleFacade
 *
 * <p>
 *     文章业务层
 * </p>
 *
 * @author chuanbai
 * @date 2024/10/18
 */
@Component
public class ArticleFacade {

    @Resource
    private ArticleDocumentRepository articleDocumentRepository;

    public ArticleDocument addArticle(ArticleDocument articleDocument){
        return articleDocumentRepository.insert(articleDocument);
    }

    public ArticleDocument queryArticle(Long id){
        Optional<ArticleDocument> articleDocumentOptional = articleDocumentRepository.findById(id);
        return articleDocumentOptional.orElseGet(ArticleDocument::new);
    }
}
